/*
 *
 *      Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: lengleng (wangiegie@gmail.com)
 *
 */

package com.pig4cloud.pig.base.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.base.api.dto.ServicesDto;
import com.pig4cloud.pig.base.api.vo.ClustersVO;
import com.pig4cloud.pig.base.api.vo.ServiceVO;
import com.pig4cloud.pig.base.api.vo.ServicesVO;
import com.pig4cloud.pig.base.service.BaseService;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.security.annotation.Inner;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;

import java.io.IOException;
import java.util.List;

import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;


/**
 * @author wyl
 * @date 2024/05/31
 */
@RestController
@AllArgsConstructor
@RequestMapping("/services")
@Tag(description = "services", name = "注册中心模块")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ServicesController {

	@Autowired
	private BaseService baseService;


	/**
	 * 查询服务列表
	 * @param page 参数集
	 * @param userDTO 查询参数列表
	 * @return 服务集合
	 */
	@Inner(false)
	@GetMapping("/page")
	@Operation(summary = "分页查询", description = "分页查询")
	public R getServices(@ParameterObject Page page,@ParameterObject ServiceVO serviceVO) throws IOException {
		Page pa = baseService.services(page,serviceVO);
		System.out.println(pa);
		return R.ok(baseService.services(page,serviceVO));
	}
	
	/**
	 * 通过服务名称获取信息
	 * @param name
	 * @return 服务信息
	 */
	@GetMapping("/details/{name}")
	public R user(@PathVariable String name) {
		List<ClustersVO> vo = baseService.service(name);
		System.out.println(vo);
		return R.ok(vo);
	}

	
}
